#ifndef _TESTMAIN_H_
#define _TESTMAIN_H_

#include<iostream>
#include<string>

#ifdef _WIN32_
#include<Windows.h>
typedef HINSTANCE MODULE_HANDLE;
#endif

#ifdef _LINUX_
#include<dlfcn.h>
typedef void * MODULE_HANDLE;
#endif

using namespace std;

MODULE_HANDLE dll_Open(string dllpath)
{
#ifdef _WIN32_
	return LoadLibraryA(dllpath.c_str());
#endif

#ifdef _LINUX_
	return dlopen(dllpath.c_str(), RTLD_NOW|RTLD_GLOBAL);
#endif
}

void dll_Close(MODULE_HANDLE h)
{
	if(h)
	{
#ifdef _WIN32_
	FreeLibrary(h);
#endif

#ifdef _LINUX_
	dlclose (h);
#endif
	}
}

void *dll_GetProc(MODULE_HANDLE h, string funname)
{
	if(h)
	{
#ifdef _WIN32_
	return (void *)GetProcAddress(h, funname.c_str());
#endif

#ifdef _LINUX_
	return dlsym(h, funname.c_str());
#endif
	}
	return NULL;
}

#endif